﻿
@{
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@using yiran.Areas.Admin.Models.Entity
@model sys_email

<body>
    <style>
        .layui-form-item .layui-input-inline {
            min-width: 190px;
            width: auto
        }
    </style>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" lay-filter="example">
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>
                        发件者名称
                    </label>
                    <div class="layui-input-inline">
                        <input style="height:38px;" type="text" value="@Model.name" name="name" required lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>
                        发件邮箱
                    </label>
                    <div class="layui-input-inline">
                        <input style="height:38px;" type="text" value="@Model.email" name="email" required lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="phone" class="layui-form-label">
                        <span class="x-red">*</span>
                        授权码
                    </label>
                    <div class="layui-input-inline">
                        <input style="height:38px;" type="password" value="@Model.password" name="password" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <a href="https://jingyan.baidu.com/article/5552ef479c6354518ffbc9dd.html" target="_blank" style="line-height:38px" class="x-red">不知道怎么获取？</a>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>
                        邮件服务器
                    </label>
                    <div class="layui-input-inline">
                        <input style="height:38px;" type="text" value="@Model.host" name="host" required lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>
                        端口号
                    </label>
                    <div class="layui-input-inline">
                        <input style="height:38px;" type="text" value="@Model.prot" name="prot" required lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>
                        是否开启SSL
                    </label>
                    <div style="line-height:38px" class="layui-input-inline">
                        <input type="checkbox" name="isssl" @(Model.isssl == 1 ? "checked" : "") lay-text="ON|OFF" lay-filter="switchTest" lay-skin="switch">
                    </div>
                </div>

                @Html.AntiForgeryToken();
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button class="layui-btn layui-btn-lg" lay-filter="add" lay-submit="">
                        修改
                    </button>
                </div>
            </form>
        </div>
    </div>
    <script>
        layui.use(['form', 'layer','element'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer,
                    upload = layui.upload;
                //监听提交
                form.on('submit(add)',
                    function (data) {
                        var dataf = data.field;
                        if (!dataf["isssl"]) {
                            dataf["isssl"] = 0;
                        } else {
                             dataf["isssl"] = 1
                        }
                    $.ajax({
                        url: '@Url.Action("Setemail","Web",new { area="Admin"})',
                        data: dataf,
			            type: "post",
			            async:true,
			            dataType: 'json',
                        success: function (data) {
                            if (data.code == 200) {
                                //发异步，把数据提交给php
                                layer.alert(data.result, {
                                    icon: 6
                                }, function () {
                                        location.reload();
                                });
                            } else {
                                 layer.msg(data.result, { icon: 0, time: 2000 });
                            }
                        },
			            error:function(xhr,errorText,errorType){
                             alert("error");
                        },
			            complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
				            if(status=='timeout'){
					            ajax.abort();
					            alert("请求超时");
				            }
			            }
		            })

                    return false;
                });

            });
    </script>
</body>
